#include<iostream>
#include<string>
using namespace std;
int main()
{
	int t = 0;
	cin >> t;
	string str1, str2;
	while (t--)
	{
		cin >> str1 >> str2;
		swap(str1[0], str2[0]);
		cout << str1 << " " << str2 << endl;
	}
	return 0;
}